<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<script type="text/javascript"
	src="static/My97DatePicker/WdatePicker.js"></script>

<div class="panel" style="height: 610px; overflow: auto;">
	<div class="panel-body pan">
	<input id="projectIds" type="hidden"  class="form-control" value="" />
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">用户名称</label>
				<div class="col-md-9">
					 <div class="input-icon">
						<input id="organizationUsername" type="text" disabled="true" class="form-control" value="" />
						<input id="organizationUserid" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">项目名称
					<span class='require'>*</span>
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select class="form-control" id="projectId" name="projectName">
						<!--  	<option value=''>--请选择--</option>
							<?for(project in projectList){?>
							<option value="${project.type}" table="${project.id}"nameZh="${project.nameZh}">${project.nameZh}</option>
							<?}?>-->
						</select>
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;height:750px;"
			id="multplediv"></div>
	</div>
</div>
<?} ?>
<script>
	var sumbitId = window.parent.getsumbitId();
	var sumbitNameZh = window.parent.getSumbitNameZh();
	$("#organizationUsername").val(sumbitNameZh);
	$("#organizationUserid").val(sumbitId);
	$(function() {
		queryJg(sumbitId);
	});
	
	//初始查询
	$(function() {
		$.ajax({
			type : "post",
			url : "organizationUserUploadquery.do",
			data : {
				"memberId" : sumbitId
			},
			async : false,
			success : function(data) {
				//alert(JSON.stringify(data));
				for(var i=0;i<data.length;i++){
					var text ="";
					var ids = data[i].id;
				    if(data[i].type == 'balance'){
				    	text +="<div class='col-lg-12' ><input id='balance_project"+data[i].id+"' type='hidden' value='' class='form-control' /><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"+data[i].nameZh+"（balance）</h4>";
				  		text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='balance_start"+data[i].id+"' type='text' class='form-control' value='' onchange=\"dateJudge('"+this.value+"','"+project+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
						text +="<div class='col-lg-4' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='balance_end"+data[i].id+"' type='text' class='form-control' value='' onchange=\"timeJudge('"+this.value+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
				    	text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>余额<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='balance_balance"+data[i].id+"' type='text' class='form-control' value='' />"
							 +"</div></div></div>";
						 text +="<div class='col-lg-12' style='width: 580px; float:left; margin-right:-20px;display:inline;'>"
						 text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
						 text += "<div class='col-md-9'><div class='input-icon'><ul>";
							$.ajax({
								type : "post",
								url : "organizationUserProduct.do",
								data:{
									"projectId":data[i].id
								},
								async: false,
								success: function(data){
									for(var i in data){
										var name = data[i].name;
											text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='"+ids+""+data[i].id+"' name='"+ids+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='"+ids+""+data[i].id+"'>"+name+"</label></li>";
									} 
								}
							});
						 text += "</ul></div></div></div>";
						    
						 text +="</div></div></div>";
				    }
				      if(data[i].type == 'time'){
				    	text +="<div class='col-lg-12' ><input id='time_project"+data[i].id+"' type='hidden' value='' class='form-control' /><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"+data[i].nameZh+"（time）</h4>";
				  		text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='time_start"+data[i].id+"' type='text' class='form-control' value='' onchange=\"dateJudge('"+this.value+"','"+project+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
						text +="<div class='col-lg-4' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='time_end"+data[i].id+"' type='text' class='form-control' value='' onchange=\"timeJudge('"+this.value+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
						 text +="<div class='col-lg-12' style='width: 580px; float:left; margin-right:-20px;display:inline;'>"
					    text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
						text += "<div class='col-md-9'><div class='input-icon'><ul>";
						$.ajax({
							type : "post",
							url : "organizationUserProduct.do",
							data:{
								"projectId":data[i].id
							},
							async: false,
							success: function(data){
								for(var i in data){
									var name = data[i].name;
										text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='"+ids+""+data[i].id+"' name='"+ids+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='"+ids+""+data[i].id+"'>"+name+"</label></li>";
								} 
							}
						});
						text += "</ul></div></div></div>";
					    
					    text +="</div></div></div>";
				    } 
				     if(data[i].type == 'count'){
				    	text +="<div class='col-lg-12' ><input id='count_project"+data[i].id+"' type='hidden' value='' class='form-control' /><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"+data[i].nameZh+"（count）</h4>";
				  		text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='count_start"+data[i].id+"' type='text' class='form-control' value='' onchange=\"dateJudge('"+this.value+"','"+project+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
						text +="<div class='col-lg-4' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='count_end"+data[i].id+"' type='text' class='form-control' value='' onchange=\"timeJudge('"+this.value+"')\" onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							 +"</div></div></div>";	
				    	text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>剩余次数<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='count_surplus"+data[i].id+"' type='text' class='form-control' value='' />"
							 +"</div></div></div>";
						/* text +="<div class='col-lg-6' style='width: 380px; float:left; margin-right:-20px;display:inline;'>"
							 + "<label for='inputUsername' class='col-md-3 control-label'>累计消费次数<span class='require'>*</span> </label>"
							 + "<div class='col-md-9'><div class='input-icon'>"
							 + "<input id='count_accumulative"+data[i].id+"' type='text' class='form-control' value='' />"
							 +"</div></div></div>"; */
						 text +="<div class='col-lg-12' style='width: 580px; float:left; margin-right:-20px;display:inline;'>"
					     text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
						 text += "<div class='col-md-9'><div class='input-icon'><ul>";
						 $.ajax({
							type : "post",
							url : "organizationUserProduct.do",
							data:{
								"projectId":data[i].id
							},
							async: false,
							success: function(data){
								for(var i in data){
									var name = data[i].name;
										text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='"+ids+""+data[i].id+"' name='"+ids+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='"+ids+""+data[i].id+"'>"+name+"</label></li>";
								} 
							}
						 });
						 text += "</ul></div></div></div>";
					    
					     text +="</div></div></div>";
				    }
				    $("#multplediv").prepend(text);
					   $.ajax({
						type : "post",
						url : "organizationUserUploadupladeText.do",
						data:{
							"memberId":sumbitId,
						},
						dataType : "json",
						success: function(data){
						//alert(JSON.stringify(data));
								for ( var i = 0; i < data.length; i++) {
								$("#projectIds").val(data[i].projectIds);
									if(data[i].type =='balance'){
										$("#balance_project"+data[i].projectId).val(data[i].id);
										$("#balance_start"+data[i].projectId).val(data[i].startTim);
										$("#balance_end"+data[i].projectId).val(data[i].endTime);
										$("#balance_balance"+data[i].projectId).val(data[i].balance);
										var projectProducts = data[i].projectProducts.split(";");
										for ( var j = 0; j < projectProducts.length; j++) {
											$("input[id="+data[i].projectId+""+ projectProducts[j] + "]").attr("checked",true);
										}
									}
									
									if(data[i].type =='time'){
										$("#time_project"+data[i].projectId).val(data[i].id);
										$("#time_start"+data[i].projectId).val(data[i].startTim);
										$("#time_end"+data[i].projectId).val(data[i].endTime);
										var projectProducts = data[i].projectProducts.split(";");
										for ( var j = 0; j < projectProducts.length; j++) {
											$("input[id="+data[i].projectId+""+ projectProducts[j] + "]").attr("checked",true);
										}
									}
									
									if(data[i].type =='count'){
										$("#count_project"+data[i].projectId).val(data[i].id);
										$("#count_start"+data[i].projectId).val(data[i].startTim);
										$("#count_end"+data[i].projectId).val(data[i].endTime);
										$("#count_surplus"+data[i].projectId).val(data[i].count);
									/* 	$("#count_accumulative"+data[i].projectId).val(data[i].countConsume); */
										var projectProducts = data[i].projectProducts.split(";");
										for ( var j = 0; j < projectProducts.length; j++) {
											$("input[id="+data[i].projectId+""+projectProducts[j] + "]").attr("checked",true);
										}
									}
									
								}
							}
					   });
					}
				}
		});
	})
	
	
	//动态构建
	var balance = '';
	var time = '';
	var count = '';
	$(document).ready(function() {
			$("#projectId").bind("change",function() {
				var project = $("#projectId").find(
						"option:selected").attr(
						"table");
				var nameZh = $("#projectId").find(
						"option:selected").attr(
						"nameZh");
				var diyseat = project+";"+$(this).val();
				var diyprojectIds = $("#projectIds").val();
				$("#projectIds").val(diyprojectIds+","+diyseat);
				var text = "";
				if ($(this).val() == 'balance'&& balance == '') {
					balance = $(this).val();
					text += "<div class='col-lg-12' ><input id='balance_project"+project+"' type='hidden' value='0' class='form-control' /><div class='panel '><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"
							+ nameZh
							+ "（"
							+ $(this).val()
							+ "）</h4>";
					text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='balance_start"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-4' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='balance_end"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>余额<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='balance_balance"+project+"' type='text' class='form-control' value='' />"
							+ "</div></div></div>";
					text += "<div class='col-lg-12' style='width: 800px; float:left; margin-right:-20px;display:inline;'>"
					text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
					text += "<div class='col-md-9'><div class='input-icon'><ul>";
					$.ajax({
							type : "post",
							url : "organizationUserProduct.do",
							data : {
								"projectId" : project
							},
							async : false,
							success : function(
									data) {
								for ( var i in data) {
									var name = data[i].name;
									text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='balance"+data[i].id+"' name='"+project+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='balance"+data[i].id+"'>"
											+ name
											+ "</label></li>";
								}
							}
						});
					text += "</ul></div></div></div>";

					text += "</div></div></div></div>";
				}
				if ($(this).val() == 'time'&& time == '') {
					time = $(this).val();
					text += "<div class='col-lg-12' ><input id='time_project"+project+"' type='hidden' value='0' class='form-control' /><div class='panel '><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"
							+ nameZh
							+ "（"
							+ $(this).val()
							+ "）</h4>";
					text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='time_start"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-4' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='time_end"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-12' style='width: 800px; float:left; margin-right:-20px;display:inline;'>"
					text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
					text += "<div class='col-md-9'><div class='input-icon'><ul>";
					$.ajax({
								type : "post",
								url : "organizationUserProduct.do",
								data : {
									"projectId" : project
								},
								async : false,
								success : function(
										data) {
									for ( var i in data) {
										var name = data[i].name;
										text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='time"+data[i].id+"' name='"+project+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='time"+data[i].id+"'>"
												+ name
												+ "</label></li>";
									}
								}
							});
					text += "</ul></div></div></div>";

					text += "</div></div></div></div>";
				}
				if ($(this).val() == 'count'&& count == '') {
					count = $(this).val();
					text += "<div class='col-lg-12' ><input id='count_project"+project+"' type='hidden' value='0' class='form-control' /><div class='panel '><div class='panel-heading'></div><div class='panel-body pan'><h4>&nbsp;&nbsp;"
							+ nameZh
							+ "（"
							+ $(this).val()
							+ "）</h4>";
					text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>生效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='count_start"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-4' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>失效时间<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='count_end"+project+"' type='text' class='form-control' value='' onclick=\"WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})\" />"
							+ "</div></div></div>";
					text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>剩余次数<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='count_surplus"+project+"' type='text' class='form-control' value='' />"
							+ "</div></div></div>";
				/* 	text += "<div class='col-lg-6' style='width: 400px; float:left; margin-right:-20px;display:inline;'>"
							+ "<label for='inputUsername' class='col-md-3 control-label'>累计消费次数<span class='require'>*</span> </label>"
							+ "<div class='col-md-9'><div class='input-icon'>"
							+ "<input id='count_accumulative' type='text' class='form-control' value='' />"
							+ "</div></div></div>"; */
					text += "<div class='col-lg-12' style='width: 800px; float:left; margin-right:-20px;display:inline;'>"
					text += "<label for='inputUsername' class='col-md-3 control-label'>产品库<span class='require'></span> </label>"
					text += "<div class='col-md-9'><div class='input-icon'><ul>";
					$.ajax({
								type : "post",
								url : "organizationUserProduct.do",
								data : {
									"projectId" : project
								},
								async : false,
								success : function(
										data) {
									for ( var i in data) {
										var name = data[i].name;
										text += "<li style='float:left;margin-right:30px;list-style-type:none;'><input id='count"+data[i].id+"' name='"+project+"' type='checkbox' value='"+data[i].id+"'/>&nbsp;&nbsp;<label for='count"+data[i].id+"'>"
												+ name
												+ "</label></li>";
									}
								}
							});
					text += "</ul></div></div></div>";

					text += "</div></div></div></div>";
				}
				$("#multplediv").prepend(text);
			});
		});

	//添加
	function save() {
		var balanceMap = {};
		var timeMap = {};
		var countMap = {};
		var ids =$("#projectIds").val();
		var projects = ids.split(",");
		for ( var j = 0; j < projects.length; j++) {
			var ptype = projects[j].split(";")[projects[j].split(";").length-1];
			var pid = projects[j].split(";")[0];
			/**balance statr*/
			if (ptype == 'balance') {
				var balance_project = [];
				$("input[name='"+pid+"']:checked").each(function() {
					balance_project.push($(this).val());
				});
				var balanceProject = '';
				for ( var i = 0; i < balance_project.length; i++) {
					balanceProject += balance_project[i] + ",";
				}
				if ($.trim($("#balance_start").val()).length < 1) {
					alert('生效时间不能为空！');
					return null;
				}
				if ($.trim($("#balance_end").val()).length < 1) {
					alert('失效时间不能为空！');
					return null;
				}
				if ($.trim($("#balance_balance").val()).length < 1) {
					alert('余额不能为空！');
					return null;
				}
				if ($.trim(balanceProject).length < 1) {
					alert('产品至少选择一个！');
					return null;
				}
				balanceMap["id"] = $("#balance_project"+pid).val();
				balanceMap["project"] = balanceProject;
				balanceMap["start"] = $("#balance_start"+pid).val();
				balanceMap["end"] = $("#balance_end"+pid).val();
				balanceMap["balance"] = $("#balance_balance"+pid).val();
				balanceMap["projectId"] = pid;
				balanceMap["organizationUserid"] = $("#organizationUserid").val();
			}
			/**balance end*/
	
			/**time statr*/
			
			if (ptype == 'time') {
				var time_project = [];
				$("input[name='"+pid+"']:checked").each(function() {
					time_project.push($(this).val());
				});
				var timeProject = '';
				for ( var i = 0; i < time_project.length; i++) {
					timeProject += time_project[i] + ",";
				}
				if ($.trim($("#time_start").val()).length < 1) {
					alert('生效时间不能为空！');
					return null;
				}
				if ($.trim($("#time_end").val()).length < 1) {
					alert('失效时间不能为空！');
					return null;
				}
				if ($.trim(timeProject).length < 1) {
					alert('产品至少选择一个！');
					return null;
				}
				timeMap["id"] = $("#time_project"+pid).val();
				timeMap["project"] = timeProject;
				timeMap["start"] = $("#time_start"+pid).val();
				timeMap["end"] = $("#time_end"+pid).val();
				timeMap["projectId"] = pid;
				timeMap["organizationUserid"] = $("#organizationUserid").val();
			}
			/**time end*/
	
			/**count statr*/
			
			if (ptype == 'count') {
				var count_project = [];
				$("input[name='"+pid+"']:checked").each(function() {
					count_project.push($(this).val());
				});
				var countProject = '';
				for ( var i = 0; i < count_project.length; i++) {
					countProject += count_project[i] + ",";
				}
				for ( var i = 0; i < count_project.length; i++) {
					countProject += count_project[i] + ",";
				}
				if ($.trim($("#count_start").val()).length < 1) {
					alert('生效时间不能为空！');
					return null;
				}
				if ($.trim($("#count_end").val()).length < 1) {
					alert('失效时间不能为空！');
					return null;
				}
				if ($.trim($("#count_surplus").val()).length < 1) {
					alert('剩余次数为空！');
					return null;
				}
				if ($.trim(countProject).length < 1) {
					alert('产品至少选择一个！');
					return null;
				}
				countMap["id"] = $("#count_project"+pid).val();
				countMap["project"] = countProject;
				countMap["start"] = $("#count_start"+pid).val();
				countMap["end"] = $("#count_end"+pid).val();
				countMap["surplus"] = $("#count_surplus"+pid).val();
				countMap["accumulative"] = '0';
				countMap["projectId"] = pid;
				countMap["organizationUserid"] = $("#organizationUserid").val();
			}
		}
		/**count end*/
		$.ajax({
			type : "post",
			url : "organizationUserUpalodEdit.do",
			data : {
				"balanceMap" : JSON.stringify(balanceMap),
				"timeMap" : JSON.stringify(timeMap),
				"countMap" : JSON.stringify(countMap),
			},
			dataType : "json",
			async : false,
			traditional : true,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.demo(1);
				;
				parent.layer.msg('编辑成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	//查询项目
	 function queryJg(jgId){
		$.ajax({
			type : "post",
			url : "queryJg.do",
			data : {
				"id" : jgId,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				var src='<option value=" ">--请选择--</option>';
				for(var i=0; i<data.length;i++){
					src += '<option value="'+data[i].type+'" table="'+data[i].id+'" nameZh="'+data[i].nameZh+'" >'+data[i].nameZh+'</option>';
				}
				$("#projectId").html(src);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	 }
	  //判断时间范围
	 function dateJudge(judgeType,dateProjectId){
	 	var startTimes = $("#"+judgeType+"_start").val();
	 	var mendId = $("#organizationUserid").val();
	 	$.ajax({
			type : "post",
			url : "goDateJudge.do",
			data : {
				"startTimes" : startTimes,
				"mendId" : mendId,
				"dateProjectId" : dateProjectId,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].judge == 'no'){
					alert('该时间段已订购！请重新选择...');
					$("#"+judgeType+"_start").val("");
				}
				if(data[0].judge == 'noNewTime'){
					alert('无法选择已过时间！请重新选择...');
					$("#"+judgeType+"_start").val("");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	 }
	 //判断时间大小
	 function timeJudge(judgeType){
	 	var startTimes = $("#"+judgeType+"_start").val();
	 	if ($.trim(startTimes).length < 1) {
				alert('请先选择生效时间！');
				$("#"+judgeType+"_end").val("");
				return null;
		}
	 	var endTimes = $("#"+judgeType+"_end").val();
	 	$.ajax({
			type : "post",
			url : "goTimeJudge.do",
			data : {
				"startTimes" : startTimes,
				"endTimes" : endTimes,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].judge == 'no'){
					alert('失效时间必须大于生效时间！');
					$("#"+judgeType+"_end").val("");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	 }
</script>